<?php
/* -----------------------------------------------------------------------------------------
   $Id: product_related_products_cat.php 2 2011-02-17 13:35:25Z akausch $

   commerce:SEO based on xt:Commerce
   
   -----------------------------------------------------------------------------------------
   based on:
   (c) 2000-2001 The Exchange Project  (earlier name of osCommerce)
   (c) 2002-2003 osCommerce(also_purchased_products.php,v 1.21 2003/02/12); www.oscommerce.com
   (c) 2003	 nextcommerce (also_purchased_products.php,v 1.9 2003/08/17); www.nextcommerce.org

   Released under the GNU General Public License
   ---------------------------------------------------------------------------------------*/
$module_smarty = new Smarty;
$module_smarty->assign('tpl_path', 'templates/'.CURRENT_TEMPLATE.'/');

if($_SESSION['customers_status']['customers_fsk18_display'] == '0')
	$fsk_lock = ' AND p.products_fsk18 != 1';

if(GROUP_CHECK == 'true')
	$group_check = " AND p.group_permission_".$_SESSION['customers_status']['customers_status_id']." = 1 ";

$path = explode('_', $cPath);
$cat = array_reverse($path);

$products_query = xtDBquery("SELECT
									p.products_id,
									pd.products_name
								FROM 
									".TABLE_PRODUCTS." p
								LEFT JOIN ".TABLE_PRODUCTS_TO_CATEGORIES." pc ON (p.products_id = pc.products_id)									
								LEFT JOIN ".TABLE_PRODUCTS_DESCRIPTION." pd ON (p.products_id = pd.products_id AND pd.language_id = '".(int) $_SESSION['languages_id']."')
								WHERE 
									categories_id='".$cat[0]."'
								AND 
									p.products_status = 1
								AND 
									p.products_id <> '".$product->data['products_id']."'
									".$fsk_lock.$group_check."
								ORDER BY RAND() LIMIT 5");

$product_related_products_cat = array();

while ($products_data = xtc_db_fetch_array($products_query, true)) {
	$product_related_products_cat[] = array(
                                    'pID' => $products_data['products_id'],
                                    'pName' => $products_data['products_name'],
                                    'prdlink' => xtc_href_link(FILENAME_PRODUCT_INFO, xtc_product_link($products_data['products_id'])));

}

$products_query = xtDBquery("SELECT 
									pc.products_id,
									pd.products_name
								FROM 
									".TABLE_PRODUCTS." p
								LEFT JOIN ".TABLE_PRODUCTS_TO_CATEGORIES." pc ON (p.products_id = pc.products_id)									
								LEFT JOIN ".TABLE_PRODUCTS_DESCRIPTION." pd ON (p.products_id = pd.products_id AND pd.language_id = '".(int) $_SESSION['languages_id']."')
								WHERE 
									p.products_id <> '".$product->data['products_id']."'
								AND 
									p.products_status = 1
									".$fsk_lock.$group_check."
								ORDER BY RAND() LIMIT 5");

$product_related_products_all = array();

while ($products_data = xtc_db_fetch_array($products_query, true)) {
    $product_related_products_all[] = array(
                                'pID' => $products_data['products_id'],
                                'pName' => $products_data['products_name'],
                                'prdlink' => xtc_href_link(FILENAME_PRODUCT_INFO, xtc_product_link($products_data['products_id'])));
}

$module_smarty->assign('PRODUCT_RELATED_CAT', $product_related_products_cat);
$module_smarty->assign('PRODUCT_RELATED_CAT_ALL', $product_related_products_all);

$module_smarty->assign('language', $_SESSION['language']);

$module_smarty->caching = 0;
$product_related_products_cat = $module_smarty->fetch(CURRENT_TEMPLATE.'/module/product_related_products_cat.html');

$info_smarty->assign('MODUL_product_related_cat', $product_related_products_cat);
?>